package com.study.mythread.juc.ticket;

/**
 * @program: java-study-of-learner
 * @description: 普通卖票 没有加入同步
 * @author: future
 * @create: 2021-01-16 20:10
 **/
public class SaleTicketV1 {
    private int num = 50;

    public static void main(String[] args) {
        SaleTicketV1 v1 = new SaleTicketV1();
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 50; i++) {
                v1.sale();
            }
        });
        thread.start();
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 50; i++) {
                v1.sale();
            }
        });
        thread1.start();
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 50; i++) {
                v1.sale();
            }
        });
        thread2.start();
    }

    public void sale() {
        if (num > 0) {
            System.out.println(Thread.currentThread().getName() + " 我们开始卖票吧：" + num--);
        }
    }
}
